<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>
<body>

<div class="row">
    <div class="col-sm-12">
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                    <div class="form-group">
                        <label class="control-label col-sm-1">国家:</label>
                        <div class="col-sm-2">
                            <select  name="productCountry" id="productCountry" class="form-control">
                                <option value="">全部分类</option>
                                <option value="CA">CA</option>
                                <option value="DE">DE</option>
                                <option value="ES">ES</option>
                                <option value="EU">EU</option>
                                <option value="FR">FR</option>
                                <option value="IT">IT</option>
                                <option value="JP">JP</option>
                                <option value="UK">UK</option>
                                <option value="US">US</option>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">渠道:</label>
                        <div class="col-sm-2">
                            <select id="productChannelId" name="productChannelId"  class="form-control">
                                <option value="">全部分类</option>
                                <%for(var chan in channel){%>
                                <option value="${chan.id}"  >${chan.channelName}</option>
                                <%}%>
                            </select>
                        </div>

                        <label class="control-label col-sm-1">品牌:</label>
                        <div class="col-sm-2">
                            <select id="productBrand" name="productBrand"  class="form-control">
                                <option value="">全部分类</option>
                                <%for(var bra in brand){%>
                                <option value="${bra.detailName}"  >${bra.detailName}</option>
                                <%}%>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">状态:</label>
                        <div class="col-sm-1">
                            <select name="productStatus"  class="form-control">
                                <option value="">全部分类</option>
                                <option value="1" >已企划</option>
                                <option value="2" >待来样</option>
                                <option value="3" >待评审</option>
                                <option value="4" >待建档</option>
                                <option value="5" >待下单</option>
                                <option value="6" >待出运</option>
                                <option value="7" >已上新</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-1">大类:</label>
                        <div class="col-sm-2">
                            <select id="productBigClassId" name="productBigClassId"  class="form-control">
                                <option value="">全部分类</option>
                                <%for(var category in category){%>
                                <option value="${category.id}"  >${category.categoryName}</option>
                                <%}%>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">中类:</label>
                        <div class="col-sm-2">
                            <select id="productMidClassId" name="productMidClassId" class="form-control">
                                <option value="">全部分类</option>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">小类:</label>
                        <div class="col-sm-2">
                            <select id="productClassId" name="productClassId" class="form-control">
                                <option value="">全部分类</option>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">产品名称:</label>
                        <div class="col-sm-1">
                            <input type="text" id="productName" name="productName" placeholder="" class="form-control">
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
        </div>
        <!-- END 右侧数据 -->
    </div>
</div>
    <form>
        <div id="toolbar" class="btn-group">
            <button  class="add-btn layui-btn layui-btn-normal layui-btn-sm" style="margin-top: -6px;margin-left: -4px">
                <i class="fa fa-plus" aria-hidden="true"></i> 新增上新流程
            </button>
            <button  class="export-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -4px">
                <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
            </button>
        </div>
    </form>
<!-- START 数据表格 -->
<!-- START 数据表格 -->
    <div class="wrapper wrapper-content">
        <table id="productTable"
               data-toolbar="#toolbar"
               data-pagination="true"
               data-resizable="true"
               data-side-pagination="server"
               data-url="/sea/product/new/findByCnd.do"
               data-page-size="15"
               class="table table-striped table-hover">
        </table>
    </div>

<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <input type="hidden" name="productId" id="productId">
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
            <input type="hidden" id="productStatus">
            <div class="productStatus form-group" style="margin-top: 15px">
                <label class="status-name control-label col-sm-2" style="max-width: 100px">评审状态</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <label class="radio-inline " style="padding-top: 9px;">
                        <input type="radio" style="margin-top: 4px;"  name="productStatus" id="optionsRadios3" value="2" checked> 通过
                    </label>
                    <label class="radio-inline close-label" style="padding-top: 9px;">
                        <input type="radio" style="margin-top: 4px;" name="productStatus" id="optionsRadios4"  value="31"> 拒绝
                    </label>
                    <label class="radio-inline" style="padding-top: 9px;">
                        <input type="radio" style="margin-top: 4px;" name="productStatus" id="optionsRadios5"  value="32"> 关闭
                    </label>
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">完成时间:</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="productDate" name="productDate" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">备注</label>
                <div class="col-sm-6" style="max-width: 400px;">
                    <textarea id="productRemark" name="productRemark" class="remark form-control" rows="7"></textarea>
                </div>
            </div>

            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>


<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui,upload'}){}%>
<script>
    laydate.render({
        elem: '#productDate',
        type: 'date',
        format: 'yyyy-MM-dd',
        trigger: 'click'
    });
    var $productTable = $('#productTable');

    $(function () {
        //新增
        $('.add-btn').on('click',function(){//新增
            layer.open({
                title: false,
                closeBtn: 0,
                type: 2,
                area: ['100%','100%'],
                skin: 'layer-ext-espresso',
                content: ['/sea/product/new/addPage.do', 'yes']
            });
        });
        // START 表格配置
        $productTable.bootstrapTable({
            pageSize:10,
            columns: [
                {
                    title: '国家',
                    field: 'productCountry',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '渠道',
                    field: 'productChannelName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '品牌',
                    field: 'productBrand',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '部门',
                    field: 'productGroup',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '商品名称',
                    field: 'productName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '大类名称',
                    field: 'productBigClassName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '中类名称',
                    field: 'productMidClassName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '小类名称',
                    field: 'productClassName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '状态',
                    field: 'productStatus',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        switch (v) {
                            case 1:
                                return '待来样';
                            case 2:
                                return '待评审';
                            case 3:
                                return '待建档';
                            case 4:
                                return '待下单';
                            case 5:
                                return '待出运';
                            case 6:
                                return '待上新';
                            case 7:
                                return '已上新';
                            case 21:
                                return '来样关闭';
                            case 31:
                                return '评审拒绝';
                            case 32:
                                return '评审关闭';
                        }
                    }
                },
                {
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                    valign: 'middle'
                },

                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                $('.edit-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    $("#productId").val(id);
                    var status=$(this).attr('data-val-status');
                    $("#productStatus").val(status);
                    var title;
                    if (status==1) {
                        title = '来样';
                        $(".status-name").text("来样状态");
                        $(".close-label").hide();
                        $('.productStatus').show();
                        $("#optionsRadios5").val(21);
                        $("#productStatus").val(2);
                        $("#optionsRadios3").val(2);
                    }
                    if(status==2){
                        title='评审';
                        $(".close-label").show();
                        $("#optionsRadios3").val(3);
                        $("#optionsRadios4").val(31);
                        $("#optionsRadios5").val(32);
                    }
                    if(status==3){
                        title='建档';
                        $(".productStatus").hide();
                        $("#productStatus").val(4);
                    }
                    if(status==4){
                        title='下单';
                        $(".productStatus").hide();
                        $("#productStatus").val(5);
                    }
                    if(status==5){
                        title='出运';
                        $(".productStatus").hide();
                        $("#productStatus").val(6);
                    }
                    if(status==6){
                        title='上新';
                        $(".productStatus").hide();
                        $("#productStatus").val(7);
                    }
                    layer.open({
                        type:1,
                        title:title,
                        area:['600px','450px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_window')
                    })
                });

                $('.detail-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        type: 2,
                        area: ['100%','100%'],
                        content: ['/sea/product/record/main.do?id='+id, 'yes']
                    });
                });
            }
        });

        // 条件查询
        $('.search-btn').on('click',function () {
            $productTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/product/new/findByCnd.do?'+$('#search-form').serialize() });
        });
    });

    // 操作菜单
    function optFormatter(value,row){
        var content='';
        switch (row.productStatus) {
            case 1:
                content += '<button class="edit-btn btn btn-xs btn-info" data-val-status="'+row.productStatus+'" data-val="'+row.id+'" title="来样"><i class="fa fa-edit"></i> 来样</button>';
                break;
            case 2:
                content += '<button class="edit-btn btn btn-xs btn-info" data-val-status="'+row.productStatus+'" data-val="'+row.id+'" title="评审"><i class="fa fa-edit"></i> 评审</button>';
                break;
            case 3:
                content += '<button class="edit-btn btn btn-xs btn-info" data-val-status="'+row.productStatus+'" data-val="'+row.id+'" title="建档"><i class="fa fa-edit"></i> 建档</button>';
                break;
            case 4:
                content += '<button class="edit-btn btn btn-xs btn-info" data-val-status="'+row.productStatus+'" data-val="'+row.id+'" title="下单"><i class="fa fa-edit"></i> 下单</button>';
                break;
            case 5:
                content += '<button class="edit-btn btn btn-xs btn-info" data-val-status="'+row.productStatus+'" data-val="'+row.id+'" title="出运"><i class="fa fa-edit"></i> 出运</button>';
                break;
            case 6:
                content += '<button class="edit-btn btn btn-xs btn-info" data-val-status="'+row.productStatus+'" data-val="'+row.id+'" title="上新"><i class="fa fa-edit"></i> 上新</button>';
                break;
        }
        content += '&nbsp;<button class="detail-btn btn btn-xs btn-default" data-val="'+row.id+'" title="查看记录"> 查看记录</button>';
        return content;
    }
    $(".export-btn").click(function () {
        window.location.href='/sea/product/new/export.do?'+$('#search-form').serialize();
    });

    $("#productBigClassId").change(function () {
        var parentId=$("#productBigClassId").val();
        getCategory(parentId,1);
    });
    $("#productMidClassId").change(function () {
        var parentId=$("#productMidClassId").val();
        getCategory(parentId,2);
    });

    function getCategory(parentId,type) {
        $.ajax({
            url:'/sea/product/category/findByParentId',
            data:{
                id:parentId
            },
            type:'post',
            success:function (data) {
                var list=data;
                if(list.length>0){
                    var category='<option value="">全部分类</option>';
                    for(var i=0;i<list.length;i++){
                        category+='<option value="'+list[i].id+'">'+list[i].categoryName+'</option>';
                    }
                    if(type=='1') {
                        $("#productMidClassId").html(category);
                    }
                    if(type=='2'){
                        $("#productClassId").html(category);
                    }
                }
            }
        });
    }

    //提交表单
    $('.save-btn').on('click',function(){
        layer.confirm('确定要修改当前状态？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            var productDate=$("#productDate").val();
            if(productDate==''){
                parent.layer.msg('请选择时间！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var produceStatus;
            if($("#productStatus").val()=='1' || $("#productStatus").val()=='2' ){
                produceStatus=$('input:radio:checked').val();
            }else{
                produceStatus=$("#productStatus").val();
            }


            layer.closeAll();
            var index=layer.load();
            $.post('/sea/product/record/usave.do',{flag:1,productStatus:produceStatus,productId:$("#productId").val(),productDate:productDate,productRemark:$("#productRemark").val()},function(data){
                if(data.ok){
                    $productTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });
</script>
</body>
</html>